package com.ruoyi.web.controller.monitorTools;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.monitorTools.domain.A2ROfEFIntrusion;
import com.ruoyi.monitorTools.domain.ElectronicFence;
import com.ruoyi.monitorTools.service.ElectronicFenceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description TODO
 * @Author wsl
 * @Date 2025-02-11 13:23
 * @Version 1.0
 */

@RestController
@Api(tags = "电子围栏")
@RequestMapping("/electronicFence")
public class ElectronicFenceController  extends BaseController {

    @Autowired
    private ElectronicFenceService electronicFenceService;

    @PostMapping
    @ApiOperation("电子围栏-add")
    public AjaxResult add(@RequestBody ElectronicFence electronicFence){
        return toAjax(electronicFenceService.insertOne(electronicFence));
    }

    @DeleteMapping
    @ApiOperation("电子围栏-删除")
    public AjaxResult delete(@RequestParam("idList") ArrayList<Integer> idList){
        return toAjax(electronicFenceService.removeByIds(idList));
    }

    @PutMapping
    @ApiOperation("电子围栏-update")
    public AjaxResult update(@RequestBody ElectronicFence electronicFence) {
        return electronicFenceService.updateByTaskIdAndRegionalId(electronicFence);
    }

    @GetMapping
    @ApiOperation("电子围栏-selectById")
    public AjaxResult selectById(Long id){
        return AjaxResult.success(electronicFenceService.selectEleById(id));
    }

    @GetMapping("listByPage")
    @ApiOperation("电子围栏-分页查询")
    public TableDataInfo list(String regionName, Integer enableStatus){
        startPage();
        List<ElectronicFence> list = electronicFenceService.listByPage(regionName, enableStatus);
        return getDataTable(list);
    }

    @GetMapping("selectOtherList")
    @ApiOperation("电子围栏-查询其他电子围栏")
    public AjaxResult selectOtherList(){
       return AjaxResult.success(electronicFenceService.selectOtherList());
    }


    @PostMapping("batchUpdateEnableStatus")
    @ApiOperation("电子围栏-批量修改状态")
    public AjaxResult batchUpdateEnableStatus(@RequestParam("idList") ArrayList<Integer> idList, @RequestParam("enableStatus") Integer enableStatus){
        return electronicFenceService.batchUpdateEnableStatus(idList, enableStatus);
    }

    @GetMapping("outOrIn")
    @ApiOperation("电子围栏-查询闯入闯出记录")
    public TableDataInfo selectBehavior(Long taskId, Integer behavior, String targetName){
        startPage();
        List<A2ROfEFIntrusion> list =  electronicFenceService.selectBehavior(taskId, behavior, targetName);
        return getDataTable(list);
    }









}
